﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JMT.Data
{
    public class JModelFactory
    {
        public static JModel Create<T>() where T : JModel
        {
            JModel jModel = null;
            if (typeof(T) == typeof(JSolution))
            {
                jModel = new JSolution();
            }
            else if (typeof(T) == typeof(JPackage))
            {
                jModel = new JPackage();
            }
            else if (typeof(T) == typeof(JDiagram))
            {
                jModel = new JDiagram();
            }
            else if (typeof(T) == typeof(JInterface))
            {
                jModel = new JInterface();
            }
            else if (typeof(T) == typeof(JClass))
            {
                jModel = new JClass();
            }
            else if (typeof(T) == typeof(JMethod))
            {
                jModel = new JMethod();
            }
            else if (typeof(T) == typeof(JProperty))
            {
                jModel = new JProperty();
            }
            else if (typeof(T) == typeof(JElement))
            {
                jModel = new JElement();
            }
            else if (typeof(T) == typeof(JGeneralization))
            {
                jModel = new JGeneralization();
            }
            else if (typeof(T) == typeof(JAggregation))
            {
                jModel = new JAggregation();
            }
            else if (typeof(T) == typeof(JAssociation))
            {
                jModel = new JAssociation();
            }
            else if (typeof(T) == typeof(JComposition))
            {
                jModel = new JComposition();
            }

            if (jModel != null)
            {
                jModel.Id = Guid.NewGuid();
                jModel.Name = JData.Current.NameCreator.GetNewName<T>();
            }

            return jModel;
        }

        public static JModel Create(string type)
        {
            JModel jModel = null;
            if (type == JConstString.TSolution)
            {
                jModel = new JSolution();
            }
            else if (type == JConstString.TPackage)
            {
                jModel = new JPackage();
            }
            else if (type == JConstString.TDiagram)
            {
                jModel = new JDiagram();
            }
            else if (type == JConstString.TInterface)
            {
                jModel = new JInterface();
            }
            else if (type == JConstString.TClass)
            {
                jModel = new JClass();
            }
            else if (type == JConstString.TMethod)
            {
                jModel = new JMethod();
            }
            else if (type == JConstString.TProperty)
            {
                jModel = new JProperty();
            }
            else if (type == JConstString.TElement)
            {
                jModel = new JElement();
            }
            else if (type == JConstString.TGeneralization)
            {
                jModel = new JGeneralization();
            }
            else if (type == JConstString.TAggregation)
            {
                jModel = new JAggregation();
            }
            else if (type == JConstString.TAssociation)
            {
                jModel = new JAssociation();
            }
            else if (type == JConstString.TComposition)
            {
                jModel = new JComposition();
            }

            if (jModel != null)
            {
                jModel.Id = Guid.NewGuid();
                jModel.Name = JData.Current.NameCreator.GetNewName(type);
            }

            return jModel;
        }
    }
}
